package com.ruoyi.aisite.controller;

import com.ruoyi.aisite.domain.AiSite;
import com.ruoyi.aisite.service.IAiSiteService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.text.Convert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * AI站点Controller
 * 
 * @author ruoyi
 */
@Controller
@RequestMapping("/aisite/site")
public class AiSiteController extends BaseController {
    private String prefix = "aisite/site";

    @Autowired
    private IAiSiteService aiSiteService;

    @GetMapping()
    public String site() {
        return prefix + "/site";
    }

    /**
     * 查询AI站点列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AiSite aiSite) {
        startPage();
        List<AiSite> list = aiSiteService.selectAiSiteList(aiSite);
        return getDataTable(list);
    }

    /**
     * 新增AI站点
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存AI站点
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AiSite aiSite) {
        return toAjax(aiSiteService.insertAiSite(aiSite));
    }

    /**
     * 修改AI站点
     */
    @GetMapping("/edit/{siteId}")
    public String edit(@PathVariable("siteId") Long siteId, ModelMap mmap) {
        AiSite aiSite = aiSiteService.selectAiSiteById(siteId);
        mmap.put("aiSite", aiSite);
        return prefix + "/edit";
    }

    /**
     * 修改保存AI站点
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AiSite aiSite) {
        return toAjax(aiSiteService.updateAiSite(aiSite));
    }

    /**
     * 删除AI站点
     */
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(aiSiteService.deleteAiSiteByIds(Convert.toLongArray(ids)));
    }
}